(ns jbtrader.test 
 (:use conducta.ui conducta.ui.swing conducta.bdd jbtrader.test.registration-story ))

(import '(org.fest.swing.fixture FrameFixture))
(import '(com.jbtrader UserRegistration))

(def frameFixture)

;; set up the frame fixture
(defn ConductaTest-setUp [_] 
   (def frameFixture (FrameFixture. (UserRegistration.)))
   (.show frameFixture)
   
   (def registration-tabs (tabbed-pane frameFixture "registration.tabs"))
   (def username (text frameFixture "user.field"))
   (def password (text frameFixture "password.field"))
   (def retype-password (text frameFixture "retype.password.field"))
   (def private-accessibility (radio frameFixture "private.button"))
   (def public-accessibility (radio frameFixture "public.button"))
   (def group-accessibility (radio frameFixture "group.button"))
   (def accessibility-level (radio-button-group [
                                          (get private-accessibility :fixture) 
                                          (get public-accessibility :fixture)
                                          (get group-accessibility :fixture)]))
   (def subscribe (checkbox frameFixture "subscribe.button"))
   (def usertype (combo frameFixture "user.type.combo"))
   ;; (def brands (list-selector frameFixture "all.brands.list"))
)

;;  Actual tests
(defn ConductaTest-testPopulateAccountInfo [_]
  (println (get ^#'Populate-account-info :doc))
  
  (Populate-account-info registration-tabs username password retype-password 
    accessibility-level subscribe usertype)
)

;;  Actual tests
(defn ConductaTest-testPopulateJukeboxPreferences [_]
  (println (get ^#'Populate-jukebox-info :doc))
  
  (select "Jukebox Preferences" registration-tabs)
  (def brands (list-selector frameFixture "all.brands.list"))
  (def selected-brands (list-selector frameFixture "selected.brands.list"))
  (def selector-button (button frameFixture "select.brand"))
  (def from-year-selector (spinner frameFixture "from.spinner"))
  (def to-year-selector (spinner frameFixture "to.spinner"))
  (def budget-selector (slider frameFixture))
  (Populate-jukebox-info registration-tabs brands selected-brands 
                         selector-button from-year-selector to-year-selector 
                         budget-selector)
)

;;  Actual tests
(defn ConductaTest-testPopulateTermsAndConditions [_]
  (println (get ^#'Agree-to-terms-and-conditions :doc))
  
  (select "Terms and Conditions" registration-tabs)
  (def register-button (button frameFixture "register.button"))
  (def i-accept-radio (radio frameFixture "agree.button"))
  (def i-dont-accept-radio (radio frameFixture "not.agree.button"))
  (def accept-options (radio-button-group [(get i-accept-radio :fixture) 
                                           (get i-dont-accept-radio :fixture)]))
  (Agree-to-terms-and-conditions 
    registration-tabs accept-options register-button)
)

;; Other GUI tests ... Test domain-agnostic GUI things: tab traversal order, 
;; resizing, etc.

;; clean-up code
(defn ConductaTest-tearDown [_] (.cleanUp frameFixture))
